﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO.Ports;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SerialPortSim.Models
{
    [Serializable]
    public class SerialPortModel
    {
        public SerialPortModel()
        {
        }
        #region CommPort    
        public string DeviceId { get; set; }
        public string Description { get; set; }
        public string DeviceInfo { get; set; }

        public ObservableCollection<SerialPortModel> GetCommPorts()
        {
            ObservableCollection<SerialPortModel> devices = new ObservableCollection<SerialPortModel>();
            string[] ports = SerialPort.GetPortNames();

            foreach (string port in ports)
            {
                devices.Add(new SerialPortModel()
                {
                    DeviceId = port,
                    DeviceInfo = port
                });
            }
            return devices;
        }
        #endregion

        #region BaudRate
        public string BaudRateName { get; set; }
        public int BaudRateValue { get; set; }
        public ObservableCollection<SerialPortModel> GetBaudRates()
        {
            ObservableCollection<SerialPortModel> returnBaudRates = new ObservableCollection<SerialPortModel>();
            returnBaudRates.Add(new SerialPortModel() { BaudRateName = "4800", BaudRateValue = 4800 });
            returnBaudRates.Add(new SerialPortModel() { BaudRateName = "9600", BaudRateValue = 9600 });
            returnBaudRates.Add(new SerialPortModel() { BaudRateName = "19200", BaudRateValue = 19200 });
            returnBaudRates.Add(new SerialPortModel() { BaudRateName = "38400", BaudRateValue = 38400 });
            returnBaudRates.Add(new SerialPortModel() { BaudRateName = "57600", BaudRateValue = 57600 });
            returnBaudRates.Add(new SerialPortModel() { BaudRateName = "115200", BaudRateValue = 115200 });
            returnBaudRates.Add(new SerialPortModel() { BaudRateName = "230400", BaudRateValue = 230400 });
            returnBaudRates.Add(new SerialPortModel() { });
            return returnBaudRates;
        }
        #endregion

    }
}
